import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/novel/book/list',
  save='/novel/book/add',
  edit='/novel/book/edit',
  deleteOne = '/novel/book/delete',
  removeIndex = '/novel/book/removeIndex',
  collection = '/novel/book/collection',
  batchCollection = '/novel/book/batchCollection',
  export = '/novel/book/export',
  deleteBatch = '/novel/book/deleteBatch',
  importExcel = '/novel/book/batchImport',
  exportXls = '/novel/book/exportXls',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 删除书籍下的所有章节
 * @param params
 * @param handleSuccess
 */
export const removeIndex = (params,handleSuccess) => {
  return defHttp.post({url: Api.removeIndex, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 采集
 * @param params
 * @param handleSuccess
 */
export const collection = (params,handleSuccess) => {
  return defHttp.post({url: Api.collection, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 导出
 * @param params
 * @param handleSuccess
 */
export const exportFun = (params,handleSuccess) => {
  return defHttp.get({url: Api.export, params,responseType: 'blob'}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchCollection = (params, handleSuccess) => {
  return defHttp.post({url: Api.batchCollection, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}
